<?php
namespace Muyuxuan\ThreePayment\three\bct\tool\Demo;
/* 宝付账簿提现接口
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

use Muyuxuan\ThreePayment\three\bct\tool\SecurityUtil\NewRsaUtil;
use Muyuxuan\ThreePayment\three\bct\tool\Util\HttpClient;
use Muyuxuan\ThreePayment\three\bct\tool\Util\Log;
use Muyuxuan\ThreePayment\three\bct\tool\Util\Tools;

require_once '../Init/init.php';

Log::EchoFormat("==========================");
Log::EchoFormat("宝付账簿提现接口");
Log::EchoFormat("==========================");


/* Header 参数*/
$HeaderPost = array();
$HeaderPost["memberId"] = $GLOBALS["WMember_Id"];//宝付提供给商户的唯一编号
$HeaderPost["terminalId"] = $GLOBALS["WTerminal_Id"];
$HeaderPost["serviceTp"] = "T-1001-013-14";//报文编号
$HeaderPost["verifyType"] = "1";//加密方式目前只有1种，请填：1

$contentData = array();       
$contentData["header"] = $HeaderPost;


$BodyData = array();  
$BodyData["version"] = "4.0.0";//版本号
$BodyData["contractNo"] = "CP610000000000188888";//客户账户号
$BodyData["transSerialNo"] = Tools::getTransid("TSN");//商户订单号
$BodyData["dealAmount"] = "10.5";//单位（元）
$BodyData["returnUrl"] = "http://10.0.60.66:8048/Demo/WithdrawReturn.php";//提现异步通知
//$BodyData["feeMemberId"] = "CP610000000000188888"; // 内扣模式
Log::EchoFormat("提现订单号：".$BodyData["transSerialNo"]);

$contentData["body"] = $BodyData;

$JsonObject = json_encode($contentData);
Log::EchoFormat("JSON：".$JsonObject);

$Data_Content = NewRsaUtil::encryptByPfx($JsonObject,$GLOBALS["PFX_FILE_PATH"],$GLOBALS["Key_Pwd"]);
$HeaderPost["content"] = $Data_Content;

$PostString  =  HttpClient::Post($HeaderPost, Tools::getUrl($HeaderPost["serviceTp"]),"json");

Log::EchoFormat("返回：".$PostString);

IF(empty($PostString)){
    throw new \Exception("返回异常！");
}
$RPostString = NewRsaUtil::decrptByPub($PostString,$GLOBALS["CER_FILE_PATH"]);

Log::EchoFormat("解密明文：".$RPostString);